
*-------------------------------------------------------------------------------
* 0. Descriptives mentioned in text
*-------------------------------------------------------------------------------	
	* Policy firm gap
	* Load nonpolicy firm data
	use "$data/cb/stacked_nonpolicy_firm_dataset.dta", clear
	keep if balanced_short==1
	drop if trt_exp==4
	drop estab_id
	egen estab_id=group(cmp_company_code cz)

	* Unique establishments
	distinct estab_id 
	local unique_estab_np=`r(ndistinct)'
	PrintEst `unique_estab_np' "unique_estab_np"	"" "%" 15.0fc "$figures_tables/text"
	
	* Unique companies
	distinct cmp_company_code 
	local unique_cmp_np=`r(ndistinct)'
	PrintEst `unique_cmp_np' "unique_cmp_np"	"" "%" 15.0fc "$figures_tables/text"
	
	* Share poaching and feeding across experiments
	replace poaching_estab=0 if poaching_estab==.
	replace feeder_estab=0 if feeder_estab==.
	collapse (max) poaching_estab feeder_estab, by(estab_id trt_exp)
	collapse (mean) poaching_estab feeder_estab, by(trt_exp)
	sum poaching_estab
	local share_poaching_estab=round(100*`r(mean)',1)
	PrintEst `share_poaching_estab' "share_poaching_estab"	"" "%" 4.0f "$figures_tables/text"
	
	sum feeder_estab
	local share_feeder_estab=round(100*`r(mean)',1)
	PrintEst `share_feeder_estab' "share_feeder_estab"	"" "%" 4.0f "$figures_tables/text"

*------------------------------------------------------------------------------------------------------------%	
* Table D1: Employment share distribution of non-policy firms across CZs in all, major and $15 VMWs
*------------------------------------------------------------------------------------------------------------%	

	* Load nonpolicy data
	use mdate cz trt_exp sample_ind tot_emp tot_emp_7_29 er_naics using "$data/cb/stacked_nonpolicy_firm_dataset.dta", clear
	drop if inlist(trt_exp,4,15,16)
		
	drop sample_ind
	gen sample_ind = (substr(string(er_naics), 1, 2) == "44" | substr(string(er_naics), 1, 2) == "45") & strlen(string(er_naics)) == 3

	* Collapse to CZ-month-exp
	collapse (sum) tot_emp tot_emp_7_29, by(mdate cz trt_exp sample_ind)
	reshape wide tot_emp tot_emp_7_29, i(mdate cz trt_exp) j(sample_ind)

	rename tot_emp0 outsample_tot
	rename tot_emp1 insample_tot
	gen tot = outsample_tot + insample_tot
	rename tot_emp_7_290 outsample_tot_7_29
	rename tot_emp_7_291 insample_tot_7_29
	gen tot_7_29 = outsample_tot_7_29 + insample_tot_7_29

	* Merge QCEW employment
	rename cz czone
	merge m:1 czone mdate using "$data/qcew/qcew_emp_cz.dta", keepusing(emp_main_ind emp_all missing_qcew_all emp_retail missing_qcew_retail) keep(1 3) nogen
	replace missing_qcew_retail = 1 if missing(emp_main_ind)
	replace missing_qcew_all = 1 if missing(emp_retail)

	* Drop time frame not in QCEW sample
	drop if mdate > tm(2023m6)

	* Calculate shares
	gen cover_tot = tot/emp_all
	gen cover_retail = insample_tot/emp_retail

	gen cover_tot_7_29 = tot_7_29/emp_all
	gen cover_retail_7_29 = insample_tot_7_29/emp_retail

	* Get rid of problematic QCEW months
	tab missing_qcew_all missing_qcew_retail
	preserve
	drop if missing_qcew_all == 1 | missing_qcew_retail == 1

	cap file close shares
	file open shares using "$figures_tables/appendix/tabled1_nonpolicy_coverage_qcew_no_missing.txt", write replace
	file write shares "\begin{threeparttable} \begin{tabular}{ccc} Experiment & Tot Emp Coverage & Retail Emp Coverage \\ \midrule " _n
	egen expid = group(trt_exp)	
	levelsof expid, local(exps)
	foreach exp in `exps' {
		qui sum cover_tot [fw = emp_all] if expid == `exp'
		local cover_tot: di %4.2f `r(mean)'
		qui sum cover_retail [fw = emp_retail] if expid == `exp'
		local cover_retail: di %4.2f `r(mean)'
		file write shares "`exp' & `cover_tot' & `cover_retail' \\" _n
	}
	file write shares "\end{tabular}" "\begin{tablenotes}" _n
	file write shares "\end{tablenotes} \end{threeparttable}"
	file close shares
	restore
	
	/*
	file write shares "Notes: Share of QCEW-reported private employment in sample CZs that is covered by large credit bureau by experiment. Sample includes only CZ-month observations with valid QCEW data for both total employment and retail employment.  Numerator limited to hourly wage workers at in-sample establishments in large credit bureau data. Column two is limited to employment in the retail sector (NAICS 44-45). Data sources: Quarterly Census of Employment and Wages; Large credit bureau." _n	
	*/

*------------------------------------------------------------------------------------------------------------%	
* Table D2: Correlation between different exposure measures
*------------------------------------------------------------------------------------------------------------%	
* Table showing correlations between different exposure measures
	* Get rid of problematic QCEW months
		* Load event info
	use "$data/cb/events.dta", clear	
	drop if eventid==4
	
	* Drop overlapping events
	drop if min(months_since_last_policy, months_until_next_policy) <= 6
	
	levelsof eventid, local(exp)
	
	rename eventid trt_exp
	tempfile event_info
	save `event_info', replace
	
	clear
	foreach experiment in `exp' {
		append using "$data/cb/all_gap_measures_`experiment'_qtrly_wage_bill.dta"
		}		
		
	merge m:1 trt_exp using `event_info'	, keep (3)
		egen expid = group(trt_exp)	

	cap file close exposure_measures
	file open exposure_measures using "$figures_tables/appendix/tabled2_correlation_exposure_measures_by_experiment.txt", write replace
	file write exposure_measures "\begin{threeparttable} \begin{tabular}{cccc} Experiment (\% of local emp.) & Own gap -- Emp. share & Own gap -- Market gap & Market gap -- Emp. share \\ \midrule " _n
	levelsof expid, local(exps)
	foreach exp in `exps' {
		qui sum employment_share_q_all if expid==`exp'
		local emp_share: di %4.2f `r(mean)'*100 
		qui corr T employment_share_q_all if expid == `exp'
		local corr_t_emp: di %4.2f `r(rho)'
		qui corr T super_gap if expid == `exp'
		local corr_t_sg: di %4.2f `r(rho)'
		qui corr super_gap employment_share_q_all if expid == `exp'
		local corr_sg_emp: di %4.2f `r(rho)'
		file write exposure_measures "`exp' (`emp_share') & `corr_t_emp' & `corr_t_sg' & `corr_sg_emp' \\" _n
	}
	file write exposure_measures "\end{tabular}" "\begin{tablenotes}" _n
	file write exposure_measures "\end{tablenotes} \end{threeparttable}"
	file close exposure_measures
		
*------------------------------------------------------------------------------------------------------------%	
* Table D3: Industries connected to policy employers by worker flows
*------------------------------------------------------------------------------------------------------------%	
	use "$data/cb/clean_policy_firm_new_hires.dta", clear
	
	replace _er_naics = 999 if _er_naics == .
	replace er_naics_name="Missing" if _er_naics==999 
	
	collapse (sum) new_hires, by( _er_naics er_naics_name )
		
	* Total new hires across all industries
	egen tot_new_hires=sum(new_hires)
	la var tot_new_hires "Total new hires"
	gen share_new_hires=100*new_hires/tot_new_hires	
	la var share_new_hires "Percentage of new hires by 2-digit NAICS"
	egen rank = rank(-new) 
	la var rank "Rank of new hire previous industry share"	

	gsort rank

	keeporder rank _er_naics er_naics_name share_new_hires 
	rename _er_naics er_naics

	replace share_new=round(share_new,2)
	gen cum_share_new_hires=sum(share_new_hires)
	
	*outsheet if rank<=10 using $data/cb/policy_firm_new_hires_previous_industry_distribution.csv, comma replace
	keep if cum_share<=84
	keep if share_new>=2
	drop rank
	tempfile hires
	save `hires'
	
	* Current industry of separations among large retailers
	
	use "$data/cb/raw_policy_to_nonpolicy_new_hires.dta", clear
	drop if cmp_company_code_previous=="other"
	
	replace er_naics=999 if er_naics==.
	replace er_naics_name="Missing" if er_naics==999

	collapse (sum) separations=freq,by( er_naics er_naics_name )

	* Total new hires across all industries
	egen tot_separations=sum(separations)
	la var tot_separations "Total separations"
	gen share_separations=100*separations/tot_separations	
	la var share_separations "Percentage of separations by 2-digit NAICS"
	egen rank = rank(-separations) 
	la var rank "Rank of separations by industry share"	
	
	gsort  rank

	keeporder rank er_naics er_naics_name share_separations 

	replace share_separations=round(share_separations,2)
	gen cum_share_separations=sum(share_separations)
	keep if share_separations>=2
	*outsheet  using $data/cb/policy_firm_separations_new_industry_distribution.csv, comma replace
	
	merge 1:1 er_naics using `hires'

* Write table

	* Get missing count
	gsort er_naics
	count
	local missing_sep = share_separations[`r(N)']
	local missing_new = share_new_hires[`r(N)']
	drop in `r(N)'

	gsort rank

	file open sumstats using "$figures_tables/appendix/tabled3_new_hire_sep_distribution.txt", write replace
	file write sumstats "\begin{threeparttable} \begin{tabular}{lcc} \toprule \toprule Industry (3-digit NAICS) & \% of separations & \% of new hires \\ \midrule" _n
	count
	foreach n of numlist 1/`r(N)' {
		local name = er_naics_name[`n']
		local sep = share_separations[`n']
		if `sep' == . {
			local sep "$<$2"
		}
		local new = share_new_hires[`n']
		if `new' == . {
			local new "$<$2"
		}
		file write sumstats "`name' & `sep' & `new' \\" _n
	}
	file write sumstats "\bottomrule \bottomrule \end{tabular} \begin{tablenotes} \footnotesize \textit{Notes:} Industry unknown for `missing_sep'\% of separations and `missing_new'\% of new hires. Data sources: Large credit bureau. \end{tablenotes} \end{threeparttable}"
	file close sumstats	

*---------------------------------------------------------------------------------------------------------------------------------%	
* Appendix Figure D1: Share of policy hires/separations from/to non-policy; share non-policy new hires/separations from/to policy  
*---------------------------------------------------------------------------------------------------------------------------------%	
	
* What share of policy hires are from non policy over same time frame
	
	use "$data/cb/clean_policy_new_hires_cz.dta", clear
	
	drop year
	gen year = yofd(dofm(mdate))
	
	drop if year == 2023
	
	collapse (sum) tot_new_hires new_hires_nonpolicy, by(year)
	
	gen share_nonpolicy = new_hires/tot
	
	graph tw scatter share year, c(l) xlab(2013(1)2022) lcolor("$dnwcrimson") msymbol(none)  ytitle("Share of new hires") xtitle("Year") 
	graph export "$figures_tables/appendix/figd1a_share_hires_from_nonpolicy.pdf", replace
/*
 title("Share of large retailer hires that are from non-policy firms") ///
		note("Notes: Numerator is new employees to the six large retailers with minimum wage policies that are linked within the" ///
			"previous year to a firm in the data that is not one of the six large retailers. Denominator is all new employees to the " ///
			"six large retailers. Data source: Large credit bureau.")
*/
* What share of all non policy hires are from policy over the full 2013-2023 period
* Load all new hires data
	foreach dateset in "201301_201712" "201801_202112" "202201_202308" {
		insheet using "$data/cb/raw/[Project Name]_result1_3_czone_allcompany_`dateset'.csv", clear
			keep if !inlist(cmp_company_code,10108, 10203, 10523, 11463, 12250, 70129 )
		tempfile newhires_`dateset'
		save `newhires_`dateset'', replace
	}
	clear
	foreach dateset in "201301_201712" "201801_202112" "202201_202308" {
		append using `newhires_`dateset''
	}
	
	* Create monthly date and year variables 
	gen str7 str_monthyear = substr(string(wt_original), 1, 4) + "-" + substr(string(wt_original), 5, 2)
	drop if strlen(string(wt_original)) == 5 // duplicates
	gen mdate = monthly(str_monthyear, "YM")
	format mdate %tm
	gen month=month(dofm(mdate))
	
	gen year=yofd(dofm(mdate))	
	
	* Rename CZ variable
	rename czone cz
		
	* Generate total new hires variable
	egen tot_new_hires=rowtotal(wage_lt8 wage_8 wage_9 wage_10 wage_11 wage_12 wage_13 wage_14 wage_15 wage_16 wage_17 wage_18 wage_19 wage_20 wage_21 wage_22 wage_23 wage_24 wage_25 wage_26 wage_27 wage_28 wage_29 wage_gt30)		
	la var tot_new_hires "Total new hires"
	egen tot_new_hires_7_29=rowtotal(wage_lt8 wage_8 wage_9 wage_10 wage_11 wage_12 wage_13 wage_14 wage_15 wage_16 wage_17 wage_18 wage_19 wage_20 wage_21 wage_22 wage_23 wage_24 wage_25 wage_26 wage_27 wage_28 wage_29)		
	la var tot_new_hires_7_29 "Total new hires with wage < $30"
	
	collapse (sum) tot_new_hires, by(year)
	
	tempfile all_np_hires
	save `all_np_hires'
	
	use "$data/cb/raw_policy_to_nonpolicy_new_hires.dta", clear
	
	drop if year == 2023

	replace cmp_company_code_previous = "policy" if cmp_company_code_previous != "other"

	collapse (sum) freq, by(year cmp_company_code_previous) 

	rename cmp previous

	reshape wide freq, i(year) j(previous) string
	
	merge 1:1 year using `all_np_hires', keep (3) nogen

	gen tot = freqo+freqp+tot_new_hires

	gen share_policy = freqp/tot
	
	graph tw scatter share year, c(l) ysc(r(0)) xlab(2013(1)2022) lcolor("$dnwcrimson") msymbol(none)  ytitle("Share of new hires") xtitle("Year") 
	graph export "$figures_tables/appendix/figd1c_share_hires_from_policy.pdf", replace

	/*
title("Share of all non policy hires that are from large retailers") ///	
	note("Notes: Numerator is new employees to firms other than the six large retailers with minimum wage policies that are linked" ///
		"to one of the six large retailers in the previous year. Denominator is all new employees to all firms excluding the six large" ///
		"retailers. Data source: Large credit bureau.")
	*/
* What share of separations from policy are to non policy

	use "$data/cb/clean_policy_separations_cz.dta", clear
	
	drop year
	gen year = yofd(dofm(mdate))
	
	drop if year == 2023
	
	collapse (sum) tot_separations sep_to_nonpolicy, by(year)
	
	gen share_nonpolicy = sep_to_nonpolicy/tot_separations
	
	graph tw scatter share year, c(l)  xlab(2013(1)2022) lcolor("$dnwcrimson") msymbol(none) ytitle("Share of separations") xtitle("Year") 
	graph export "$figures_tables/appendix/figd1b_share_sep_to_nonpolicy.pdf", replace
	/*
title("Share of large retailer separations that are to non policy companies") ///
	note("Notes: Numerator is employees separated from the six large retailers with minimum wage policies that are linked" ///
		"to a firm in the data that is not one of the six large retailers in the following year. Separation date for the" ///
		"numerator is the date of hire at the new firm. Denominator is all employees separated from the six large retailers" ///
		"by date of termination. Data source: Large credit bureau.")
	*/
	
* What share of separations from non policy are to policy

	* Load full separations data
	foreach dateset in "201301_201712" "201801_202112" "202201_202308" {
		insheet using "$data/cb/raw/result1_2_czone_allcompany_v2_`dateset'.csv", clear
		keep if !inlist(cmp_company_code,10108, 10203, 10523, 11463, 12250, 70129 )
		tempfile separations_`dateset'
		save `separations_`dateset'', replace
	}
	clear
	foreach dateset in "201301_201712" "201801_202112" "202201_202308" {
		append using `separations_`dateset''
	}

	* Create monthly date and year variables 
	gen str7 str_monthyear = substr(string(date_of_termination), 1, 4) + "-" + substr(string(date_of_termination), 5, 2)
	gen mdate = monthly(str_monthyear, "YM")
	format mdate %tm
	*replace mdate=mdate+1
	gen month=month(dofm(mdate))
	gen year=yofd(dofm(mdate))	
	
	* Rename CZ variable
	rename czone cz
	
	* Generate total new hires variable
	egen tot_separations=rowtotal(wage_lt8 wage_8 wage_9 wage_10 wage_11 wage_12 wage_13 wage_14 wage_15 wage_16 wage_17 wage_18 wage_19 wage_20 wage_21 wage_22 wage_23 wage_24 wage_25 wage_26 wage_27 wage_28 wage_29 wage_gt30)		
	la var tot_separations "Total separations"
	egen tot_separations_7_29=rowtotal(wage_lt8 wage_8 wage_9 wage_10 wage_11 wage_12 wage_13 wage_14 wage_15 wage_16 wage_17 wage_18 wage_19 wage_20 wage_21 wage_22 wage_23 wage_24 wage_25 wage_26 wage_27 wage_28 wage_29)		
	la var tot_separations_7_29 "Total separations with wage < $30"
	egen tot_separations_7_15=rowtotal(wage_lt8 wage_8 wage_9 wage_10 wage_11 wage_12 wage_13 wage_14 wage_15)		
	la var tot_separations_7_15 "Total separations with wage < $16"	

	* Replace
	egen id = group(cmp_company_code cz)
	xtset id mdate
	foreach var of varlist tot_separations* {
		gen adj_`var' = `var'
	}

	foreach var of varlist tot_separations* {
		replace adj_`var' = L2.`var' if date_of_termination>=202307
	}		

	* Keep adjusted variables only, except total employment
	rename tot_separations tot_separations_unadj
	drop tot_separations_7_29 tot_separations_7_15	
	rename adj_* *	
	
	collapse (sum) tot_separations, by(year)
	
	tempfile all_np_separations
	save `all_np_separations'
	
	insheet using "$data/cb/raw/[Project Name]_result1_7_czone_nonpol_pol.csv", clear
	
	gen year = substr(string(wt_date_of_termination), 1, 4)
	destring year, replace
	
	drop if year == 2023
	
	replace cmp_company_code_new = "policy" if cmp_company_code_n != "other"
	
	collapse (sum) freq, by(year cmp_company_code_new) 

	rename cmp new

	reshape wide freq, i(year) j(new) string
	
	merge 1:1 year using `all_np_separations', keep (3) nogen 
	
	gen tot = freqo+freqp + tot_separations
	
	gen share_policy = freqp/tot
	
	graph tw scatter share year, c(l) ysc(r(0)) xlab(2013(1)2022) lcolor("$dnwcrimson") msymbol(none) ytitle("Share of separations") xtitle("Year") 
	graph export "$figures_tables/appendix/figd1d_share_sep_to_policy.pdf", replace
	/*
	 title("Share of other firm separations that are to large retailers") ///
	 note("Notes: Numerator is employees separated from a firm in the data that is not one of the six large retailers that are" ///
	"linked to employment at one of the large retailers in the following year. Denominator is all employees separated from the" ///
	"firms other than the six large retailers. Data source: Large credit bureau.")
	*/

*------------------------------------------------------------------------------------------------------------%	
* Appendix Table D4: on predictive power of poaching/feeder flag
*------------------------------------------------------------------------------------------------------------%		
	
* Poaching estab flag predictive of hiring from large retailer in post period; feeder estab flag predictive of employees separating to large retailer in post.
	* Tempfile of clean nonpolicy firm data
	use "$data/cb/clean_nonpolicy_firm_cz.dta", clear
	keep cmp_company_code cz mdate
	contract cmp_company_code cz mdate
	drop _freq
	preserve
	
	* Store tempfile of archive to mdate crosswalk
	insheet using "$data/cb/documentation/archive_mdate_crosswalk.csv", clear
	tempfile archive_mdate_crosswalk
	save `archive_mdate_crosswalk', replace
	
	* Read in events dataset and select events
	use "$data/cb/events.dta", clear
	
	* Drop overlapping events
	drop if min(months_since_last_policy, months_until_next_policy) <= 6
	drop if eventid == 4
	
	* List experiments
	levelsof eventid, local(exp)
	
	* Start building tables
	global estab ""
	global firm ""
	
	foreach experiment in `exp' {	
		
		* Keep relevant row
		use in `experiment' using "$data/cb/events.dta", clear
		
		* Identify date
		merge 1:1 archive using `archive_mdate_crosswalk'
		
		* Store relevant parameters
		foreach vr in cmp_company_code mw share_affected archive mdate months_since_last_policy months_until_next_policy {
			local `vr'=`vr'[1]
		}
		local bmw=`mw'-1
		local amw=`mw'-1
		
		clear
		
		noi di in green "Experiment `experiment': " in yellow `"`cmp_company_code' (`mw') `mdate'"'
		
		restore
		preserve
		
		* Fill in experiment parameters
		gen etime=mdate-`mdate'-1
		* Restrict to within a year of event
		local event_start = -12
		local event_end = 11
		keep if inrange(etime, `event_start',`event_end')
		drop etime
		
		* Poaching estab
		merge m:1 cmp_company_code cz mdate using "$data/cb/raw_policy_to_nonpolicy_new_hires_collapsed.dta", keepusing(cz cmp_company_code mdate new_hires`cmp_company_code')
		gen pre_year = _merge == 3 & mdate < `mdate' & !missing(new_hires`cmp_company_code') & new_hires`cmp_company_code' > 0 
		gen pre = mdate < `mdate' & !missing(new_hires`cmp_company_code') & new_hires`cmp_company_code' > 0
		gen post = mdate >= `mdate' & !missing(new_hires`cmp_company_code') & new_hires`cmp_company_code' > 0
		collapse (max) pre_year pre post, by(cmp_company_code cz)

		reg post pre_year, r
		local b_year_poach_estab = _b[pre_year]
		local b_year_poach_estab: di %4.2g `b_year_poach_estab'
		local se_year_poach_estab = _se[pre_year]
		local se_year_poach_estab: di %4.3f `se_year_poach_estab'
		di "`b_year_poach_estab' (`se_year_poach_estab')"
		reg post pre, r
		local b_pre_poach_estab = _b[pre]
		local b_pre_poach_estab: di %4.2g `b_pre_poach_estab'
		local se_pre_poach_estab = _se[pre]
		local se_pre_poach_estab: di %4.3f `se_pre_poach_estab'
		di "`b_pre_poach_estab' (`se_pre_poach_estab')"
	
		* Poaching firm
		collapse (max) pre_year pre post, by(cmp_company_code)
		reg post pre_year, r
		local b_year_poach_firm = _b[pre_year]
		local b_year_poach_firm: di %4.2g `b_year_poach_firm'
		local se_year_poach_firm = _se[pre_year]
		local se_year_poach_firm: di %4.3f `se_year_poach_firm'
		di "`b_year_poach_firm' (`se_year_poach_firm')"
		reg post pre, r
		local b_pre_poach_firm = _b[pre]
		local b_pre_poach_firm: di %4.2g `b_pre_poach_firm'
		local se_pre_poach_firm = _se[pre]
		local se_pre_poach_firm: di %4.3f `se_pre_poach_firm'
		di "`b_pre_poach_firm' (`se_pre_poach_firm')"
			
		restore
		preserve

		* Fill in experiment parameters
		gen etime=mdate-`mdate'-1
		* Restrict to within a year of event
		local event_start = -12
		local event_end = 11
		keep if inrange(etime, `event_start',`event_end')
		drop etime
		
		* Feeding estab
		merge m:1 cmp_company_code cz mdate using "$data/cb/raw_policy_to_nonpolicy_separations_collapsed.dta", keepusing(cz cmp_company_code mdate separations_to_policy`cmp_company_code')
		gen pre_year = _merge == 3 & mdate < `mdate' & !missing(separations_to_policy`cmp_company_code') & separations_to_policy`cmp_company_code' > 0 
		gen pre = mdate < `mdate' & !missing(separations_to_policy`cmp_company_code') & separations_to_policy`cmp_company_code' > 0
		gen post = mdate >= `mdate' & !missing(separations_to_policy`cmp_company_code') & separations_to_policy`cmp_company_code' > 0
		collapse (max) pre_year pre post, by(cmp_company_code cz)
		
		reg post pre_year, r
		local b_year_feed_estab = _b[pre_year]
		local b_year_feed_estab: di %4.2g `b_year_feed_estab'
		local se_year_feed_estab = _se[pre_year]
		local se_year_feed_estab: di %4.3f `se_year_feed_estab'
		di "`b_year_feed_estab' (`se_year_feed_estab')"
		reg post pre, r
		local b_pre_feed_estab = _b[pre]
		local b_pre_feed_estab: di %4.2g `b_pre_feed_estab'
		local se_pre_feed_estab = _se[pre]
		local se_pre_feed_estab: di %4.3f `se_pre_feed_estab'
		di "`b_pre_feed_estab' (`se_pre_feed_estab')"
	
		* Feeding firm

		collapse (max) pre_year pre post, by(cmp_company_code)
		reg post pre_year, r
		local b_year_feed_firm = _b[pre_year]
		local b_year_feed_firm: di %4.2g `b_year_feed_firm'
		local se_year_feed_firm = _se[pre_year]
		local se_year_feed_firm: di %4.3f `se_year_feed_firm'
		di "`b_year_feed_firm' (`se_year_feed_firm')"
		reg post pre, r
		local b_pre_feed_firm = _b[pre]
		local b_pre_feed_firm: di %4.2g `b_pre_feed_firm'
		local se_pre_feed_firm = _se[pre]
		local se_pre_feed_firm: di %4.3f `se_pre_feed_firm'
		di "`b_pre_feed_firm' (`se_pre_feed_firm')"
	
		* Write
		global estab "$estab `experiment' & `b_year_poach_estab' (`se_year_poach_estab') & `b_pre_poach_estab' (`se_pre_poach_estab') & `b_year_feed_estab' (`se_year_feed_estab') & `b_pre_feed_estab' (`se_pre_feed_estab') \\"
		global firm "$firm `experiment' & `b_year_poach_firm' (`se_year_poach_firm') & `b_pre_poach_firm' (`se_pre_poach_firm') & `b_year_feed_firm' (`se_year_feed_firm') & `b_pre_feed_firm' (`se_pre_feed_firm') \\"
		
		di "$estab"
		di "$firm"
		
	}

	* Save table
	cap file close prediction
	file open prediction using "$figures_tables/appendix/tabled4_poach_feed_predict.txt", write replace
	file write prediction "\begin{tabular}{ccccc} \toprule \toprule &\multicolumn{2}{c}{Increased probability}&\multicolumn{2}{c}{Increased probability} \\ &\multicolumn{2}{c}{of post-treatment poach}&\multicolumn{2}{c}{of post-treatment feed} \\ Experiment & When poach & When poach & When feed & When feed \\ & in prior year & in all prev. years & in prior year & in all prev. years \\ \cmidrule(lr){2-3}\cmidrule(lr){4-5}"
	file write prediction "$estab"
	file write prediction "\bottomrule \bottomrule \end{tabular}"
	file close prediction


